﻿Imports Microsoft.VisualBasic
Imports System.Data

<System.ComponentModel.DataObjectAttribute(True)> _
Public Class BLL_AddTrainingCourseGroupMapping

    Public Sub New()
        ' 
        ' TODO: 在此加入建構函式的程式碼 
        ' 
    End Sub

    'SELECT 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.[Select])> _
    Public Function BLL_Select(ByVal GroupId As Integer) As DataTable

        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("SELECT A.Id,B.CourseName,B.Hour,A.TeacherName,A.StartTime,A.EndTime ")
        sql.AppendFormat("FROM TrainingCourseGroupMapping A ")
        sql.AppendFormat("left join TrainingCourse B on A.CourseId=B.Id ")
        sql.AppendFormat("WHERE GroupId={0}; ", GroupId)
        Return dat.GetData(sql)

    End Function

    'Update
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update)> _
    Public Function BLL_Update(ByVal StartTime As String, ByVal EndTime As String, ByVal TeacherName As String, ByVal UpdateBy As String, ByVal original_Id As Integer) As Integer
        'Public Function BLL_Update(ByVal StartTime As String, ByVal EndTime As String, ByVal TeacherName As String, ByVal UpdateBy As String, ByVal original_Id As Integer) As Integer

        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("UPDATE TrainingCourseGroupMapping SET ")
        sql.AppendFormat("StartTime = '{0}' ", StartTime)
        sql.AppendFormat(",EndTime = '{0}' ", EndTime)
        sql.AppendFormat(",TeacherName = '{0}' ", TeacherName)
        sql.AppendFormat(",UpdateBy = '{0}' ", UpdateBy)
        sql.AppendFormat(",UpdateDate = getdate() ")
        sql.AppendFormat("WHERE Id = {0}; ", original_Id)
        dat.AccData(sql)

        Return 1

    End Function

    'Delete 
    <System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete)> _
    Public Function BLL_Delete(ByVal original_Id As Integer) As Integer

        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.AppendFormat("DELETE TrainingCourseGroupMapping WHERE Id={0};", original_Id)

        dat.AccData(sql)
        Return 1

    End Function

End Class
